<div id="an_radio_box">
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">子题目内容</label>
		<div class="layui-input-block">
			<!-- 加载编辑器的容器 -->
		    <script id="container1" name="danxuan[title]" type="text/plain">
		        <{$topic_info.subject_text|default:""}>
		    </script>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">题目答案A</label>
			<div class="layui-input-block">
				<input type="text" name="danxuan[radio_text][1]"  lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
			</div>
		</div>

		<div class="layui-inline">
			<input type="radio" name="danxuan[an_radio]" value="1" checked="checked" title="正确答案">
		</div>

		<div class="layui-inline">
			<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">题目答案B</label>
			<div class="layui-input-block">
				<input type="text" name="danxuan[radio_text][2]"  lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
			</div>
		</div>
		
		<div class="layui-inline">
			<input type="radio" name="danxuan[an_radio]" value="2" title="正确答案">
		</div>

		<div class="layui-inline">
			<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label"></label>
		<a href="javascript:;" class="layui-btn layui-btn-primary add_radio"><i class="layui-icon"></i>新增选项</a>
	</div>

	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">答案解析</label>
		<div class="layui-input-block">
			<textarea name="danxuan[analysis]" placeholder="请输入内容" class="layui-textarea"></textarea>
		</div>
	</div>
</div>
<script>
	layui.use(['form'], function(){
		var form = layui.form();
		form.render();

		$(".add_radio").click(function(){
			var _this = $(this);
			var letter = new Array();
			letter = <{$letter|json_encode}>;
			var radio_total = _this.closest("#an_radio_box").find("input[type='radio']").length;
			var index = radio_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<div class="layui-inline">';
			html +=	'<label class="layui-form-label">题目答案'+letter[index-1]+'</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="text" name="danxuan[radio_text]['+index+']"  lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">';
			html +=	'</div>';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<input type="radio" name="danxuan[an_radio]" value="'+index+'" title="正确答案">';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>';
			html +=	'</div>';
			html +=	'</div>';
			_this.closest(".layui-form-item").before(html);
			form.render('radio');
		});

		$( document ).on( "click", ".delete_result", function() {

	    var _this = $(this);
		var resultid = _this.attr("resultid");
		var parent = _this.closest(".layui-form-item").parent();
		var total = parent.find("input[type=radio]").length;
		var id = parent.attr("id");
		if(total <= 2){
			layer.msg("无法删除，因为至少需要两个答案", {icon:5, anim: 5});
			return false;
		}
		if(_this.closest(".layui-form-item").find("input[type='radio']").is(':checked')){
			layer.msg("无法删除正确答案", {icon:5, anim: 5});
			return false;
		}
		if(resultid > 0){
			if(confirm('删除后将无法还原,确定要删除吗?')){
			
			}else{
				return false
			}
			$.ajax({
				type: "POST",
				url: "/topic/ignore_del_topic_result",
				dataType:"json",
				data:{resultid:resultid},
				success: function(result){
					layer.close(ii);
					if(result.error == 1){
						layer.msg(result.msg, {icon:5, anim: 5});
						return false;
					}
					form.render('select');
				}
			});
		}
		_this.closest(".layui-form-item").remove();
  	});
	});

</script>